package com.lcc.springconfig.component;

import com.lcc.springconfig.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.net.SocketTimeoutException;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class BeanLifeComponent {

    private User user;
    //实例化
    public BeanLifeComponent() {
        System.out.println("执行构造方法");
    }

    @Qualifier("user")
    @Autowired
    //属性赋值
    public void setUser(User user) {
        this.user = user;
        System.out.println("属性注入");
    }

    //初始化--->工作中用的多些
    @PostConstruct
    public void init(){
        System.out.println("执行初始化方法");
    }

    //使用Bean
    public void use(){
        System.out.println("执行use方法");
    }

    //销毁，当该方法不写的是也可以通过ApplicationContext进行销毁
    @PreDestroy
    public void destroy(){
        System.out.println("执行destroy方法");
    }
}
